import axios from 'axios'

const state = {
    products: [
        // {
        //     name: '小熊即热电热水器',
        //     price: 239,
        //     img: 'https://img14.360buyimg.com/n7/jfs/t1/159059/26/1725/121283/5ff4211cE4db5c845/5088b414f61d2a13.jpg',
        //     num: 4400,
        //     shop: '小熊京东自营旗舰店',
        //     id: 1
        // },
        // {
        //     name: '米家踢脚线电暖器E',
        //     price: 499,
        //     img: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1600695132.80131541.jpg',
        //     num: 8952,
        //     shop: '小米京东自营旗舰店',
        //     id: 2

        // },
        // {
        //     name: '米家踢脚线电暖器',
        //     price: 599,
        //     img: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1572315753.91481212.jpg',
        //     num: 6432,
        //     shop: '小米京东自营旗舰店',
        //     id: 3
        // },
        // {
        //     name: '米家踢脚线电暖器1S',
        //     price: 649,
        //     img: 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1599536467.27169261.jpg',
        //     num: 6500,
        //     shop: '小米京东自营旗舰店',
        //     id: 4
        // },
        // {
        //     name: 'iPhone12',
        //     price: 5699,
        //     img: 'https://img10.360buyimg.com/n7/jfs/t1/132022/23/12216/60913/5f86195bEacd08599/c5dc348d3f943324.jpg',
        //     num: 11000,
        //     shop: 'Apple苹果京东自营旗舰店',
        //     id: 5
        // }
    ]
}

const mutations = {
    setProducts(state, payload) {
        state.products = payload
    }
}

const actions = {
    async getProducts({ commit }) {
        const { data } = await axios({
            method: 'GET',
            url: 'http://127.0.0.1:3000/product/data'
        })
        commit('setProducts', data)
    }
}

const getters = {}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}